package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.RcRegistrationConvention;
import com.macro.mall.service.RcRegistrationConventionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * RcRegistrationConvention的路由接口服务
 * 
 * @author 
 *
 */
@Slf4j
@RestController
@RequestMapping("RcRegistrationConventionController")
@Api(tags = "志愿者活动报名管理", description = "")
public class RcRegistrationConventionController {

	/** RcRegistrationConventionService服务 */
	@Autowired
	private RcRegistrationConventionService rcRegistrationConventionService;
	
	/**
	 * 查询所有RcRegistrationConvention数据的方法
	 * @return
	 */
	@GetMapping(value = "/list", produces = {"application/json;charset=UTF-8"})
	public CommonResult find(@ApiParam(value = "手机号") @RequestParam(value = "mobile", required = false) String mobile,
                             @ApiParam(value = "姓名") @RequestParam(value = "name", required = false) String name,
                             @ApiParam(value = "志愿者活动id") @RequestParam(value = "rcId", required = false) Integer rcId,
                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        RcRegistrationConvention build = RcRegistrationConvention.builder().mobile(mobile).userName(name).handleId(rcId).build();
        return CommonResult.success(CommonPage.restPage(rcRegistrationConventionService.find(build, pageNum, pageSize)));
	}
	
	/**
	 * 通过id查询RcRegistrationConvention数据的方法
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/findOne", produces = {"application/json;charset=UTF-8"})
	public CommonResult findOne(@RequestParam(name="id") Integer id) {
		return CommonResult.success(rcRegistrationConventionService.findOne(id));
	}
	
	/**
	 * 插入RcRegistrationConvention属性不为空的数据方法
	 * @param value
	 * @return
	 */
	@PostMapping(value = "/save", produces = {"application/json;charset=UTF-8"})
	public CommonResult save(@RequestBody RcRegistrationConvention value) {
        rcRegistrationConventionService.saveNotNull(value);
		return CommonResult.success(null);
	}
	
	/**
	 * 更新RcRegistrationConvention属性不为空的数据方法
	 * @param value
	 * @return
	 */
	@PostMapping(value = "/update", produces = {"application/json;charset=UTF-8"})
	public CommonResult update(@RequestBody RcRegistrationConvention value) {
        rcRegistrationConventionService.updateNotNullById(value);
		return CommonResult.success(null);
	}

	/**
	 * 通过id删除RcRegistrationConvention数据方法
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/delete", produces = {"application/json;charset=UTF-8"})
	public CommonResult delete(@RequestParam(name="id") Integer id) {
        rcRegistrationConventionService.deleteById(id);
        return CommonResult.success(null);
	}
}
